package com.xu.myTest;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.xu.model.Student;
import com.xu.model.Teacher;

import java.util.List;

/**
 * 对象转json字符
 */
public class Object2Json {

    public static void main(String[] args) {
        Student student1 = new Student("001", "静静");
        Student student2 = new Student("002", "小明");
        List<Student> listStudent = Lists.newArrayList();
        listStudent.add(student1);
        listStudent.add(student2);
        Teacher teacher = new Teacher("我是老师", listStudent);

        String studentJson = JSONObject.toJSONString(student1,false);
        String teacherJson = JSONObject.toJSONString(teacher,true);

        System.out.println(studentJson);
        System.out.println(teacherJson);

    }


}
